SRC = ./src
INC = ./inc
OBJ = ./obj
BIN = ./bin

SRCS = $(wildcard $(SRC)/*.c)
OBJS = $(patsubst %.c, $(OBJ)/%.o, $(notdir $(SRCS)))

TARGET_NAME = main
TARGET_PATH = $(BIN)/$(TARGET_NAME)

CFLAGS = -g -I $(INC)

all: prepare $(TARGET_PATH)			# 结合第 22 行

$(TARGET_PATH): $(OBJS)
	gcc $^ -lpthread -o $@

$(OBJ)/%.o: $(SRC)/%.c
	gcc $(CFLAGS) -c $< -o $@

.PHONY:prepare					# 补上这两句用
prepare:					# 以新建文件夹
#	@if [ ! -d $(OBJ) ]; then mkdir $(OBJ); fi
#	@if [ ! -d $(BIN) ]; then mkdir $(BIN); fi
	[ -d $(OBJ) ] || mkdir $(OBJ)
	[ -d $(BIN) ] || mkdir $(BIN)


.PHONY:clean
clean:
	rm $(OBJS) $(TARGET_PATH)

.PHONY:run
run:$(TARGET_PATH)
	./bin/main
